/**
 * 
 */
package de.hft_stuttgart.dsa.ctt.processing.yuruz;

import java.util.ArrayList;

import de.hft_stuttgart.dsa.ctt.model.Course;
import de.hft_stuttgart.dsa.ctt.model.CourseAssignmentMatrix;
import de.hft_stuttgart.dsa.ctt.model.Curriculum;
import de.hft_stuttgart.dsa.ctt.model.ProblemInstance;

/**
 * @author Ali Yuruz
 */
public class CurriculumChecker implements IChecker {
	private ProblemInstance problemInstance;

	public CurriculumChecker(ProblemInstance pInstance) {
		this.problemInstance = pInstance;
	}

	@Override
	public boolean isAssignable(Course courseToCheck, CourseAssignmentMatrix assignmentMatrix, int selectedPeriodSlot) {
		
		if(-1 == selectedPeriodSlot){
			return false;
		}
		ArrayList<String> courseIdList;		
		for (Curriculum curriculum : problemInstance.getCurricula().getCurricula()) {
			courseIdList = new ArrayList<String>();
			for (Course course : curriculum.getCourses()) {
				courseIdList.add(course.getCourseId());
			}
			if (courseIdList.contains(courseToCheck.getCourseId())) {
				for (Object courseObject : assignmentMatrix.getPeriodRoomMatrix()[selectedPeriodSlot]) {
					String courseObjectId = ((Course) courseObject).getCourseId();
					if (courseObjectId == null) {
						continue;
					} else if (courseObjectId.equals(courseToCheck.getCourseId())) {
						continue;
					} else if (courseIdList.contains(courseObjectId)) {
						return false;
					}
				}
			}

		}
		return true;
	}

}
